/*
 * Copyright 2009-2010 Nanjing RedOrange ltd (http://www.red-orange.cn)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package redora.client;

import redora.client.Persistable.Scope;
/**
 * Service layer that allows you to communicate with the server. Redora will
 * generate service objects for each pojo in your object model implementing this
 * interface at ...rdo.gwt.service.
 * @author Nanjing RedOrange (www.red-orange.cn)
 * @param <T> GWT pojo
 */
public interface Service<T extends Persistable> {

    public enum ResponseStatus {
        success, brViolated, expired, refused
    }

    /** Creates a finder url */
    String url(int defaultFinder, String[] params);
    String url(int defaultFinder, Long params);
    String url(int defaultFinder);
    void finder(String url, Scope scope);
    void findById(Long id, Persistable.Scope scope);
    void findById(Long[] id, Persistable.Scope scope);
    void persist(T pojo);
    void delete(T pojo);
    void trash(T pojo);

    /**
     * Provides a direct link to the cache. If the object is not found, a new object is instantiated and returned.
     * @param id (Optional) pojo id
     * @return Requested object form cache, if the object is not in the cache, or the given id is null,
     *          a new instance of T is returned.
     */
    T cache(Long id);
    boolean useCache(Long id, Scope scope);
    Long[] cache(String url);
    boolean useCache(String url);
}
